package com.cote.douhahou.pretloan.msg;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.TextView;

import com.google.android.material.bottomsheet.BottomSheetDialog;
import com.cote.douhahou.pretloan.R;

public class DatePAkomapalendickerDialog extends BottomSheetDialog {

    private final String title_akomapalend;
    private final OnDateAkomapalendPickListener onDatePickListener_akomapalend;

    public DatePAkomapalendickerDialog(Context context, String title, OnDateAkomapalendPickListener onDatePickListener){
        super(context, R.style.Theme_AkomapaLend_BottomDialogStyle);
        this.title_akomapalend = title;
        this.onDatePickListener_akomapalend = onDatePickListener;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_date);

        getWindow().setBackgroundDrawableResource(R.color.transparent);
        getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));

        init_akomapalend();
    }

    private void init_akomapalend(){

        TextView titleTv = findViewById(R.id.ddp_tv_title);
        Button doneBtn = findViewById(R.id.ddp_btn_done);

        titleTv.setText(title_akomapalend);

        DatePicker datePicker = findViewById(R.id.ddp_datepicker);
        if (datePicker == null) return;
        datePicker.setCalendarViewShown(false);

        doneBtn.setOnClickListener(v -> {
            int month = datePicker.getMonth() + 1;
            int day = datePicker.getDayOfMonth();
            String monthStr = month<10 ? "0"+month:String.valueOf(month);
            String dayStr = day<10 ? "0"+day:String.valueOf(day);
            String date = datePicker.getYear()+"-"+monthStr+"-"+dayStr;
            if (onDatePickListener_akomapalend != null) onDatePickListener_akomapalend.onDatePick_akomapalend(date);
            DatePAkomapalendickerDialog.this.dismiss();
        });
    }

}
